package com.atguigu.java;
class window implements Runnable{
    private int tick=100;
//    Object obj=new Object();
    @Override
    public void run() {

            while (true) {
                synchronized (this) {
                    try {
                        Thread.sleep(100);
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                    if (tick > 0) {
                    System.out.println(Thread.currentThread().getName() + "买票，票号为" + tick);
                    tick--;
                } else {
                    break;
                }

            }
        }
    }
}

public class WindowTest1 {
    public static void main(String[] args) {


   window w =new window();
   Thread T1=new Thread(w);
    Thread T2=new Thread(w);
    Thread T3=new Thread(w);
    T1.setName("窗口1");
    T2.setName("窗口2");
    T3.setName("窗口3");
    T1.start();
        T2.start();
        T3.start();
    }

}
